#ifndef __SEMAPHORE__
#define __SEMAPHORE__
#include "Thread.h"

class Semaphore{

 private:
 // List *head,*tail; // list of blocked threads
  Mutex* S1; // this mutex is for guarding the wake and value fields while updating the number of blocked threads and wake threads aka the Critical Section
  Mutex* S2;// this mutex controls the sleeping arrangement it blocks other threads when they want access
  int m_wake; // number of threads to wake up
  int m_value; //the number of blocked processes

 public:
  Semaphore(int value); 
  ~Semaphore();
  void setValue(int value);
  int getValue();

  // if no thread is locking, this will now lock, otherwise this will be blocked (atomic)
  //this will protect before entering the Critical Section
  void down();

  // release the Semaphore, if some thread is blocked, wake one of the blocked threads (atomic)
  //this is for releasing the lock after the critical section
  void up();
};
#endif

